<?php
class MessageThreadDTO {
	
	public $threadId;
	public $subject;
	
	/**
	 * User message DTO
	 */
	public $userMessages;
	
	public $displayUser;
	public $lastMessageCreated;
	public $displayMessage;
	/**
	 * Show message thread read or not.
	 */
	public $read;
	
	/**
     * Users involved in the message thread.
     * 
     * @return return users involved in the message thread
     */
	public function getUsers() {
		$users = array();
		foreach ($this->userMessages as $userMessage) {
			
			$user = $userMessage->targetUser;
			$users[$user->id] = $user;
			$user = $userMessage->creator;
			$users[$user->id] = $user;
		}
		return $users;
	}
	
	/**
	 * Get display user info in the thread list.
	 * if inbox, then show the latest user send to loggedInUser, exclude himself;
	 * if sent, then show the latest user who loggedInUser send to, exclude himself.
	 * 
	 * @param $loggedInUser
	 * @param $type inbox or sent
	 * @deprecated
	 */
	public function getUserShowInThreadList($loggedInUser=null, $type="inbox") {
		if ($type=="inbox") {
			return MessageThread::findLastReplyUserInThread($loggedInUser, $this->threadId);
		} else if ($type=="sent") {
			
		}
	}
}
?>